import { computed, ref, watchEffect } from 'vue';
import { useRoute } from 'vue-router';

/**
 * @description 路由白名单
 * @param {*} whiteList 
 * @returns 
 */

export const useNotOnRouterWhiteList = (whiteList = []) => {
    const route = useRoute()
    const status = computed(() => !whiteList.includes(route.name))
    return status
}


/**
 * 获取路由的参数 /xxx
 */
export const useLinkedRouteParam = (type, isNum = true) => {
    const route = useRoute()
    const currentParam = ref("")
    watchEffect(() => {
        const param = route.params[type]
        currentParam.value = isNum ? Number(param) : param
    })
    return currentParam
}

/**
 * @description 获取路由参数 ?type=xxx
 * @param {*} type 路由地址后面的query 参数
 * @returns 
 */
export const useRouteQuery = type => {
    const route = useRoute()
    return route.query[type]
}
